// 获取视频时长
const getVideoDuration = src => {
    return new Promise((res, rej) => {
        const v = document.createElement('video');

        if (typeof src === 'string') {
            v.src = src;
        }
        else {
            v.src = URL.createObjectURL(src);
        }
        v.autoplay = 'autoplay';

        v.play();

        v.addEventListener('loadedmetadata', () => {
            +v.duration && res(v.duration);
            !+v.duration && res(null);
        });
        v.addEventListener('durationchange', () => {
            +v.duration && res(v.duration);
            !+v.duration && res(null);
        });
        v.addEventListener('error', () => {
            res(null);
        });

    });

};

export default getVideoDuration;